<template>
	<uni-nav-bar title="历史班次" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view class="package_sale datas" style="padding: 10px 0px;">
		<uni-datetime-picker v-model="range" type="daterange" :border="false" :clear-icon="false" rangeSeparator="至"
			@change="change" />
	</view>
	<view class="package_sale" style="padding:0px">
		<view class="space-between" v-for="item in workList" :key="item.id"
			@click="navTo('Sale/checkWork/historyDetail?id='+item.id)">
			<view>{{item.title}}</view>
			<uni-icons type="right" size="20"></uni-icons>
		</view>
		<Popu v-if="workList.length<1" :pageHeight="pageHeight" text="暂无历史班次"></Popu>
	</view>
</template>

<script setup lang="ts">
	import { navBack, navTo } from '@/utils/navigator';
	import Popu from '@c/earthPushing/common/popu.vue';
	import { ref } from 'vue';
	import { toPublish } from '@mqtt';
	import { showLoading } from '@/utils/prompt';
	import { getStaffBanList } from '@/gql/earthPushing/checkWork';
	import { format,subDays } from 'date-fns';
	import { getDriverID } from '@/stores/driverID';
	const staff_id = getDriverID();
	let now = new Date();
	let end = format(now, 'yyyy-MM-dd');
	let daysAgo = subDays(now, 6);
	let start = format(daysAgo, 'yyyy-MM-dd');
	const range = ref([start, end]);
	const workList = ref([])
	const lastPage = ref(1);
	const currentPage = ref(1);
	const pageHeight = ref();
	uni.getSystemInfo({
		success: function (res) {
			pageHeight.value = res.windowHeight - 128;
		},
	});
	workLists()
	function workLists() {
		showLoading()
		const payload = {
			query: getStaffBanList,
			variables: {
				page: currentPage.value,
				start,
				end,
				staff_id: staff_id
			},
		};
		toPublish(
			'ql/staff/getStaffBanList',
			payload,
			(obj : any) => {
				const { getStaffBanList } = obj.data;
				workList.value = [...workList.value, ...getStaffBanList.list];
				lastPage.value = getStaffBanList.lastpage;
			}
		);
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
		if (currentPage.value < lastPage.value) {
			currentPage.value++;
			workLists();
		}
	}
	/**
	 * 时间筛选
	 * @param sta  开始时间
	 * @param en  结束时间
	 */
	function change([sta, en]) {
		start = sta;
		end = en;
		currentPage.value = 1
		workList.value = []
		workLists()
	}
</script>

<style scoped lang="less">
	.space-between {
		padding: 30rpx;
		box-sizing: border-box;
		border-bottom: 1px solid #eee;
	}
</style>
<style>
	.datas>>>.uni-date__x-input {
		font-size: 32rpx !important;
	}

	.datas>>>.uni-date-x {
		font-size: 32rpx !important;
	}

	.datas>>>.uni-icons {
		font-size: 48rpx !important;
	}

	.datas>>>.uni-date-x {
		padding: 0px 0px 0px 10rpx;
	}

	.datas>>>.select-picker {
		justify-content: flex-end;
		width: 200rpx;
	}

	.datas>>>.select-picker {
		font-size: 26rpx;
	}
</style>